package com.lusheng.demo02.config;


// 配置 MyBatis-Plus 的核心功能（逻辑删除、分页插件、性能监控），
// 依赖 MyBatis-Plus 框架，需在 Mapper 接口使用前配置。

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

// mybatis-plus插件
@Configuration
public class EduConfig {
    //逻辑删除
    @Bean
    public ISqlInjector sqlInjector(){
        return new LogicSqlInjector();
    }
    //分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }

    @Bean
    @Profile({"dev","test"})//设置dev test环境开启
    public PerformanceInterceptor performanceInterceptor(){
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        performanceInterceptor.setMaxTime(500);//ms超过此处设置的ms则sql不执行
        performanceInterceptor.setFormat(true);//设置格式化sql
        return performanceInterceptor;
    }
}
